-
Notifications
You must be signed in to change notification settings - Fork 6
chore/version-management #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
版本信息的更新后的类图classDiagram
class VersionInfo {
-version: str
-git_info: dict
-b2v_info: dict
+get_version(): str
+get_git_info(): dict
+get_b2v(): dict
+get_full_version_info(): tuple[str, dict, dict]
}
class GitInfo {
-branch: str
-commit: str
-commit_short: str
-commit_time: str
-commit_author: str
-commit_message: str
}
class BuildInfo {
-build_number: str
-build_date: str
-build_type: str
}
VersionInfo -- GitInfo : contains
VersionInfo -- BuildInfo : contains
文件级别变更
提示和命令与 Sourcery 互动
自定义您的体验访问您的 仪表板 以:
获取帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request introduces version management using Sequence diagram for status command with version infosequenceDiagram
participant User
participant Ariadne (Bot)
participant core
participant utils.version_info
User->>Ariadne (Bot): issues status command
Ariadne (Bot)->>core: Retrieves runtime information
Ariadne (Bot)->>utils.version_info: get_full_version_info()
utils.version_info-->>Ariadne (Bot): version, git_info, b2v_info
Ariadne (Bot)->>Ariadne (Bot): Formats status message with version info
Ariadne (Bot)-->>User: Sends status message
Updated class diagram for version informationclassDiagram
class VersionInfo {
-version: str
-git_info: dict
-b2v_info: dict
+get_version(): str
+get_git_info(): dict
+get_b2v(): dict
+get_full_version_info(): tuple[str, dict, dict]
}
class GitInfo {
-branch: str
-commit: str
-commit_short: str
-commit_time: str
-commit_author: str
-commit_message: str
}
class BuildInfo {
-build_number: str
-build_date: str
-build_type: str
}
VersionInfo -- GitInfo : contains
VersionInfo -- BuildInfo : contains
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @g1331 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider using a dedicated settings file (e.g.,
settings.toml
) instead of environment variables for build information. - The
bump.py
script is a nice addition, but it might be simpler to just usebump2version
directly in a Makefile.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 2 issues found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
utils/bump.py
Outdated
sys.exit(1) | ||
|
||
|
||
def run_bumpversion(part, new_version=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider creating a helper function to encapsulate subprocess execution and error handling to avoid repetition across multiple functions like run_bumpversion, update_uv_lock, and generate_changelog, improving code maintainability and readability.
Actionable Recommendation:
Consolidate the repeated subprocess invocations and error handling into a helper function. This centralizes the logic and reduces duplication.
Steps:
-
Create a helper function:
def run_command(cmd, success_msg=None, error_msg="命令执行失败"): try: result = subprocess.run(cmd, capture_output=True, text=True) if result.returncode != 0: print(f"❌ {error_msg}: {result.stderr}") sys.exit(1) if success_msg: print(success_msg) return result.stdout except Exception as e: print(f"❌ {error_msg}: {e}") sys.exit(1)
-
Refactor
run_bumpversion
:def run_bumpversion(part, new_version=None): cmd = ["bump2version"] if new_version: cmd += ["--new-version", new_version] cmd.append(part) run_command(cmd, success_msg="✅ 版本号已更新", error_msg="bump2version 执行失败") return True
-
Refactor similar functions (e.g.,
update_uv_lock
,generate_changelog
):def update_uv_lock(): if not os.path.exists("uv.lock"): print("⚠️ 未找到 uv.lock,跳过") return run_command(["uv", "lock"], success_msg="✅ uv.lock 已更新", error_msg="uv lock 执行失败") def generate_changelog(version: str): cmd = ["git-cliff", "--tag", f"v{version}", "-o", "CHANGELOG.md"] run_command(cmd, success_msg="✅ changelog 已生成", error_msg="changelog 生成失败")
These changes keep all functionality intact while reducing repetitive error handling and subprocess logic.
@@ -0,0 +1,102 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using a dedicated version file and relative imports to simplify version information handling and avoid modifying sys.path.
To reduce complexity without reverting functionality, consider removing the temporary sys.path
manipulation by placing your version information in a dedicated file within the package. This lets you use a standard relative import and isolates fallback logic. For example:
-
Create a dedicated version file
Incore/version.py
, define:__version__ = "1.2.3" # your current version
-
Import version info using relative import
Replace the dynamicsys.path
adjustment with a relative import:try: from core.version import __version__ except ImportError as e: logger.error(f"导入版本信息失败: {e}") __version__ = fallback_version()
-
Isolate fallback logic
Define a helper for fallback reading:def fallback_version() -> str: try: import tomli with open(Path(__file__).parent.parent / "pyproject.toml", "rb") as f: data = tomli.load(f) return data.get("project", {}).get("version", "0.0.0") except Exception as e: logger.error(f"读取版本信息失败: {e}") return "0.0.0"
This approach eliminates temporary sys.path
modifications while keeping functionality intact and simplifying error handling.
utils/bump.py
Outdated
return line.split("=")[1].strip() | ||
except Exception as e: | ||
print(f"❌ 读取 .bumpversion.cfg 失败: {e}") | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Remove redundant pass statement (remove-redundant-pass
)
pass |
utils/bump.py
Outdated
|
||
def get_base_version(version: str) -> str: | ||
match = re.match(r"\d+\.\d+\.\d+", version) | ||
return match.group(0) if match else version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Replace m.group(x) with m[x] for re.Match objects (use-getitem-for-re-match-groups
)
return match.group(0) if match else version | |
return match[0] if match else version |
result.update( | ||
{ | ||
"branch": repo.active_branch.name, | ||
"commit": commit.hexsha, | ||
"commit_short": commit.hexsha[:7], | ||
"commit_time": str(commit.authored_datetime), | ||
"commit_author": commit.author.name, | ||
"commit_message": commit.message.strip(), | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Merge dictionary updates via the union operator (dict-assign-update-to-union
)
result.update( | |
{ | |
"branch": repo.active_branch.name, | |
"commit": commit.hexsha, | |
"commit_short": commit.hexsha[:7], | |
"commit_time": str(commit.authored_datetime), | |
"commit_author": commit.author.name, | |
"commit_message": commit.message.strip(), | |
} | |
) | |
result |= { | |
"branch": repo.active_branch.name, | |
"commit": commit.hexsha, | |
"commit_short": commit.hexsha[:7], | |
"commit_time": str(commit.authored_datetime), | |
"commit_author": commit.author.name, | |
"commit_message": commit.message.strip(), | |
} |
0354d26
to
d406e10
Compare
a373231
to
79dc111
Compare
…ate repository URL
…ect version updates
好的,这是将拉取请求摘要翻译成中文的结果:
Sourcery 总结
为项目添加版本管理和信息显示功能,包括版本跟踪、git 信息检索和变更日志生成
新功能:
增强功能:
构建:
杂项:
Original summary in English
Summary by Sourcery
Add version management and information display functionality to the project, including version tracking, git information retrieval, and changelog generation
New Features:
Enhancements:
Build:
Chores: